#include "slitherFilter.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

uint16_t fifoBuf[FIFO_BUF_MAX_LENGTH];
size_t fifoIndex = 0;
bool fifoState = false;

void showFifo(void)
{
    int i = 0;
    while (i < FIFO_BUF_MAX_LENGTH)
    {
        printf("%d ", fifoBuf[i++]);
    }
    printf("\n-------------------- \n");
}

void fifo(uint16_t data)
{
    fifoIndex %= FIFO_BUF_MAX_LENGTH;
    fifoBuf[fifoIndex] = data;
    ++fifoIndex;
}

double fifoAverage(void)
{
    int sum = 0;

    for (int i = 0; i < FIFO_BUF_MAX_LENGTH; ++i)
    {
        sum += fifoBuf[i];
    }
    return sum / (double) FIFO_BUF_MAX_LENGTH;
}
